ifeq (${BUILD_OUTPUT_PATH},)
export BUILD_OUTPUT_PATH=$(shell pwd)
endif

CC = gcc
TARGET = clogd

INC_DIR = include

CFLAGS = -Wall -Wextra -g -I$(INC_DIR)
CFLAGS += -DSUBSYS_NAME=$(TARGET)

INC = -I../liblog/include
INC += -I$(BUILD_OUTPUT_PATH)/../include
INC += -I../libclog/include

ifeq ($(TARGET_MODE),debug)
CFLAGS += -DLOG_DEBUG
$(info info : debug mode enabled)
else
$(info info : release mode enabled)
endif

LDFLAGS = -L$(BUILD_OUTPUT_PATH)/../libclog/ -lclog -lpthread -lm
LDFLAGS += -lrt -Wl,-rpath=./

.PHONY: all all_32 clean

SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c, $(BUILD_OUTPUT_PATH)/%.o, $(SRCS))
EXE_OBJECT = $(BUILD_OUTPUT_PATH)/$(TARGET)

all all_32:$(EXE_OBJECT)

$(BUILD_OUTPUT_PATH)/%.o: %.c
	@mkdir -p $(abspath $(dir $@))
	$(CC) $(CFLAGS) $(INC) -g -o $@ -c $<

$(EXE_OBJECT): $(OBJS)
	@mkdir -p $(abspath $(dir $@))
	$(CC) $(OBJS) $(LDFLAGS) -o $@

clean:
	rm -rf $(OBJS) $(EXE_OBJECT)